<?php

namespace app\webapi\vms\service;

use app\webapi\common\BaseService;
use app\webapi\vms\model\DistributionMediaModel;
use library\OWException;
use think\facade\Filesystem;
use think\facade\Request;

/**
 * @辅助服务类
 */
class AuxiliaryService extends BaseService
{
    public function getDistributionMediaList()
    {
        return DistributionMediaModel::select();
    }

    /**
     * @desc 本地图片上传
     * @param $files
     * @return array
     * @author zhaozhiwei
     * @time 2023/12/14-16:33
     */
    public function uploadImages($files){
        $res=[];
        foreach ($files as $file) {
            $fileName = Filesystem::disk('public')->putFile('image',$file);
            if (!$fileName){
                throw new OWException('上传图片失败');
            }
            $imageUrl =Request::domain(). "/storage/".$fileName;

            array_push($res,['url'=>$imageUrl]);
        }

        return $res;
    }
}